package com.book.controller;



import com.book.pojo.Author;
import com.book.pojo.Book;
import com.book.result.Result;
import com.book.service.AuthorService;
import com.book.vo.AuthorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
<<<<<<< HEAD
 * @author cxy
 * @since 2023-10-11 21:58:42
=======
 * @author cc
 * @since 2023-10-11 21:57:48
>>>>>>> a45ef284ff029011b55ef4d830c2b996023ef30c
 */
@RestController
@RequestMapping("/author")
public class AuthorController {

    @Autowired
    private AuthorService authorService;

    //根据作者id查询其作品数量
    @GetMapping("/getBookNumByAuthorId")
    public Result getBookNumByAuthorId(@RequestParam Long id){
        int num = authorService.getBookNumByAuthorId(id);
        return Result.OK().setData(num);
    }

    //查询作者信息
    @GetMapping("getAuthorById")
    public Result getAuthorById(@RequestParam Long id){
        List<Author> list =  authorService.getAuthorById(id);
        return Result.OK().setData(list);
    }

    //查询作者个人中心有关信息 注册天数，粉丝数量，更新进度
    @GetMapping("getAuthorCenterById")
    public Result getAuthorCenterById(@RequestParam Long id){
        AuthorVo list =  authorService.getAuthorCenterById(id);
        return Result.OK().setData(list);
    }

    //作者自己修改作者信息
    @PutMapping("updateAuthor")
    public Result updateAuthor(@RequestBody Author author){
        authorService.updateAuthor(author);
        return Result.OK();
    }



}
